package com.sfac.javaSpringBoot.modules.account.controller;

import com.github.pagehelper.PageInfo;
import com.sfac.javaSpringBoot.modules.account.entity.Role;
import com.sfac.javaSpringBoot.modules.account.service.RoleService;
import com.sfac.javaSpringBoot.modules.common.entity.Result;
import com.sfac.javaSpringBoot.modules.common.entity.SearchBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api")
public class RoleController {
    @Autowired
    private RoleService roleService;


//    127.0.0.1/role/insert   post
//{"roleName":"管理员"}
    @PostMapping(value = "/role",consumes = "application/json")
    public Result<Role> insertRole(@RequestBody Role role){
        return roleService.insertRole(role);
    }
//    127.0.0.1/role/edit

    @PutMapping(value = "/role",consumes = "application/json")
    public Result<Role> EditRole(@RequestBody Role role){
        return roleService.editRole(role);
    }
//    127.0.0.1/role/delete/3
    @DeleteMapping("/role/{id}")
    public Result<Role> deleteRoleById(@PathVariable int id){
        return roleService.deleteRole(id);
    }
//    127.0.0.1/role/query/
    @GetMapping("/role/{id}")
    public List<Role> queryById(@PathVariable String id){
           return roleService.queryById(id);
    }
    @GetMapping("/roles")
    public List<Role> getRoles() {
        return roleService.getRoles();
    }

    /**
     * 127.0.0.1/api/roles ---- post
     * {"currentPage":"1","pageSize":"5","orderBy":"id","direction":"desc","keyWord":""}
     */
    @PostMapping(value = "/roles", consumes = "application/json")
    public PageInfo<Role> getRolesBySearchBean(@RequestBody SearchBean searchBean) {
        return roleService.getRolesBySearchBean(searchBean);
    }
}
